package Controllers;

import Information.PostInfo;
import Information.UserInfo;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static Application.ReadFileToString.readFile;

public class PageSiteController extends Application implements Initializable {
    @FXML
    public Label GDXZ;//工大小站Label
    @FXML
    private Pane top;//顶栏
    @FXML
    private Pane Tabsbar;//标签栏
    @FXML
    private Pane Postsite;//帖子栏
    @FXML
    private ImageView logo;
    @FXML
    private TextField searchBar;//搜索框
    @FXML
    private Button searchButton;//搜索按钮
    @FXML
    private ImageView search;//搜索按钮
    @FXML
    private Button homeButton;//主页
    @FXML
    private ImageView create;//新建按钮
    @FXML
    private ImageView draftBox;//草稿箱按钮
    @FXML
    private Button phomeButton;//个人首页按钮
    @FXML
    private Button settingButton;//设置按钮
    @FXML
    private Label text1;//第一推荐框
    @FXML
    private ImageView commentImg1;
    @FXML
    private ImageView likeImg1;
    @FXML
    private Label comment1;
    @FXML
    private Label like1;
    @FXML
    private ImageView textImg1;//第1个框的图片
    @FXML
    private Label text2;//第2推荐框
    @FXML
    private ImageView commentImg2;
    @FXML
    private ImageView likeImg2;
    @FXML
    private Label comment2;
    @FXML
    private Label like2;
    @FXML
    private ImageView textImg2;//第2个框的图片
    @FXML
    private Label text3;//第3推荐框
    @FXML
    private ImageView commentImg3;
    @FXML
    private ImageView likeImg3;
    @FXML
    private Label comment3;
    @FXML
    private Label like3;
    @FXML
    private ImageView textImg3;//第3个框的图片
    @FXML
    private Label text4;//第4推荐框
    @FXML
    private ImageView commentImg4;
    @FXML
    private ImageView likeImg4;
    @FXML
    private Label comment4;
    @FXML
    private Label like4;
    @FXML
    private ImageView textImg4;//第4个框的图片
    @FXML
    private Label text5;//第5推荐框
    @FXML
    private ImageView commentImg5;
    @FXML
    private ImageView likeImg5;
    @FXML
    private Label comment5;
    @FXML
    private Label like5;
    @FXML
    private ImageView textImg5;//第5个框的图片
    @FXML
    private Label text6;//第6推荐框
    @FXML
    private ImageView commentImg6;
    @FXML
    private ImageView likeImg6;
    @FXML
    private Label comment6;
    @FXML
    private Label like6;
    @FXML
    private ImageView textImg6;//第6个框的图片
    @FXML
    private Label text7;//第7推荐框
    @FXML
    private ImageView commentImg7;
    @FXML
    private ImageView likeImg7;
    @FXML
    private Label comment7;
    @FXML
    private Label like7;
    @FXML
    private ImageView textImg7;//第7个框的图片
    @FXML
    private Label text8;//第8推荐框
    @FXML
    private ImageView commentImg8;
    @FXML
    private ImageView likeImg8;
    @FXML
    private Label comment8;
    @FXML
    private Label like8;
    @FXML
    private ImageView textImg8;//第8个框的图片
    @FXML
    private Label text9;//第9推荐框
    @FXML
    private ImageView commentImg9;
    @FXML
    private ImageView likeImg9;
    @FXML
    private Label comment9;
    @FXML
    private Label like9;
    @FXML
    private ImageView textImg9;//第9个框的图片
    @FXML
    private Label text10;//第10推荐框
    @FXML
    private ImageView commentImg10;
    @FXML
    private ImageView likeImg10;
    @FXML
    private Label comment10;
    @FXML
    private Label like10;
    @FXML
    private ImageView textImg10;//第10个框的图片
    @FXML
    private ImageView follow;//关注
    @FXML
    private Label followNum;//关注数
    @FXML
    private ImageView fans;//粉丝
    @FXML
    private Label fansNum;//粉丝数
    @FXML
    private ImageView history;//历史
    @FXML
    private ImageView collect;//收藏
    @FXML
    private Button tag1;//标签1
    @FXML
    private Button tag2;//标签2
    @FXML
    private Button tag3;//标签3
    @FXML
    private Button tag4;//标签4
    @FXML
    private Button tagsManagement;//标签管理
    @FXML
    private ImageView userImg;//当前用户头像
    @FXML
    private ImageView mypost;//我的帖子
    @FXML
    private ImageView tagImg1;//标签图片
    @FXML
    private ImageView tagImg2;
    @FXML
    private ImageView tagImg3;
    @FXML
    private ImageView tagImg4;
    @FXML
    private ImageView tagImg5;
    @FXML
    private ImageView tagImg6;
    @FXML
    private ImageView tagImg7;
    @FXML
    private ImageView tagImg8;
    @FXML
    private ImageView tagImg9;
    @FXML
    private ImageView tagImg10;
    @FXML
    private Label tagText1;//帖子的标签
    @FXML
    private Label tagText2;
    @FXML
    private Label tagText3;
    @FXML
    private Label tagText4;
    @FXML
    private Label tagText5;
    @FXML
    private Label tagText6;
    @FXML
    private Label tagText7;
    @FXML
    private Label tagText8;
    @FXML
    private Label tagText9;
    @FXML
    private Label tagText10;

    private UserInfo userInfo = new UserInfo();//用户信息,用来在controller之间传递用户信息

    private PostInfo postInfo1 = new PostInfo();//十个帖子对象
    private PostInfo postInfo2 = new PostInfo();
    private PostInfo postInfo3 = new PostInfo();
    private PostInfo postInfo4 = new PostInfo();
    private PostInfo postInfo5 = new PostInfo();
    private PostInfo postInfo6 = new PostInfo();
    private PostInfo postInfo7 = new PostInfo();
    private PostInfo postInfo8 = new PostInfo();
    private PostInfo postInfo9 = new PostInfo();
    private PostInfo postInfo10 = new PostInfo();

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        try(
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/UserPosts/currentUser.ser")))
        {
            try {//读取当前用户对象
                userInfo = (UserInfo) ois.readObject();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        home();
    }
    @Override
    public void start(Stage primaryStage) {
        try {
            AnchorPane root = FXMLLoader.load(getClass().getResource("/Resources/PageSite.fxml"));
            Scene scene = new Scene(root, 1293.0, 840.0);
            scene.getStylesheets().add(getClass().getResource("/Resources/PageSite.css").toExternalForm());
            primaryStage.getIcons().add(new Image("/Images/logoblue.png"));
            primaryStage.setTitle("首页");
            primaryStage.setScene(scene);
            primaryStage.setResizable(false);
            primaryStage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    //设置各个帖子对象信息
    public void setPostInfo1(String postObject1){
        if(new File(postObject1).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject1)))
            {
                try {//读取第一个帖子对象
                    postInfo1 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo2(String postObject2){
        if(new File(postObject2).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject2)))
            {
                try {//读取第二个帖子对象
                    postInfo2 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo3(String postObject3){
        if(new File(postObject3).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject3)))
            {
                try {//读取第三个帖子对象
                    postInfo3 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo4(String postObject4){
        if(new File(postObject4).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject4)))
            {
                try {//读取第四个帖子对象
                    postInfo4 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo5(String postObject5){
        if(new File(postObject5).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject5)))
            {
                try {//读取第五个帖子对象
                    postInfo5 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo6(String postObject6){
        if(new File(postObject6).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject6)))
            {
                try {//读取第六个帖子对象
                    postInfo6 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo7(String postObject7){
        if(new File(postObject7).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject7)))
            {
                try {//读取第七个帖子对象
                    postInfo7 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo8(String postObject8){
        if(new File(postObject8).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject8)))
            {
                try {//读取第八个帖子对象
                    postInfo8 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo9(String postObject9){
        if(new File(postObject9).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject9)))
            {
                try {//读取第九个帖子对象
                    postInfo9 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void setPostInfo10(String postObject10){
        if(new File(postObject10).exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObject10)))
            {
                try {//读取第十个帖子对象
                    postInfo10 = (PostInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    //设置显示内容
    public void setPostDisplay1(){
        //第一个
        if(new File(postInfo1.getTextPath()).exists()){
            text1.setText(readFile(postInfo1.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo1.getImg()).exists()){
            textImg1.setImage(new Image("file:"+postInfo1.getImg()));//设置图片
        }
        comment1.setText(String.valueOf(postInfo1.getComments()));//设置评论数
        like1.setText(String.valueOf(postInfo1.getLikes()));//设置点赞数
        tagText1.setText(String.valueOf(postInfo1.getTag()));//设置帖子标签
    }
    public void setPostDisplay2(){
        //第二个
        if(new File(postInfo2.getTextPath()).exists()){
            text2.setText(readFile(postInfo2.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo2.getImg()).exists()){
            textImg2.setImage(new Image("file:"+postInfo2.getImg()));//设置图片
        }
        comment2.setText(String.valueOf(postInfo2.getComments()));//设置评论数
        like2.setText(String.valueOf(postInfo2.getLikes()));//设置点赞数
        tagText2.setText(String.valueOf(postInfo2.getTag()));//设置帖子标签
    }
    public void setPostDisplay3(){
        //第三个
        if(new File(postInfo3.getTextPath()).exists()){
            text3.setText(readFile(postInfo3.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo2.getImg()).exists()){
            textImg3.setImage(new Image("file:"+postInfo3.getImg()));//设置图片
        }
        comment3.setText(String.valueOf(postInfo3.getComments()));//设置评论数
        like3.setText(String.valueOf(postInfo3.getLikes()));//设置点赞数
        tagText3.setText(String.valueOf(postInfo3.getTag()));//设置帖子标签
    }
    public void setPostDisplay4(){
        //第四个
        if(new File(postInfo4.getTextPath()).exists()){
            text4.setText(readFile(postInfo4.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo4.getImg()).exists()){
            textImg4.setImage(new Image("file:"+postInfo4.getImg()));//设置图片
        }
        comment4.setText(String.valueOf(postInfo4.getComments()));//设置评论数
        like4.setText(String.valueOf(postInfo4.getLikes()));//设置点赞数
        tagText4.setText(String.valueOf(postInfo4.getTag()));//设置帖子标签
    }
    public void setPostDisplay5(){
        //第五个
        if(new File(postInfo5.getTextPath()).exists()){
            text5.setText(readFile(postInfo5.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo5.getImg()).exists()){
            textImg5.setImage(new Image("file:"+postInfo5.getImg()));//设置图片
        }
        comment5.setText(String.valueOf(postInfo5.getComments()));//设置评论数
        like5.setText(String.valueOf(postInfo5.getLikes()));//设置点赞数
        tagText5.setText(String.valueOf(postInfo5.getTag()));//设置帖子标签
    }
    public void setPostDisplay6(){
        //第六个
        if(new File(postInfo6.getTextPath()).exists()){
            text6.setText(readFile(postInfo6.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo6.getImg()).exists()){
            textImg6.setImage(new Image("file:"+postInfo6.getImg()));//设置图片
        }
        comment6.setText(String.valueOf(postInfo6.getComments()));//设置评论数
        like6.setText(String.valueOf(postInfo6.getLikes()));//设置点赞数
        tagText6.setText(String.valueOf(postInfo6.getTag()));//设置帖子标签
    }
    public void setPostDisplay7(){
        //第七个
        if(new File(postInfo7.getTextPath()).exists()){
            text7.setText(readFile(postInfo7.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo7.getImg()).exists()){
            textImg7.setImage(new Image("file:"+postInfo7.getImg()));//设置图片
        }
        comment7.setText(String.valueOf(postInfo7.getComments()));//设置评论数
        like7.setText(String.valueOf(postInfo7.getLikes()));//设置点赞数
        tagText7.setText(String.valueOf(postInfo7.getTag()));//设置帖子标签
    }
    public void setPostDisplay8(){
        //第八个
        if(new File(postInfo8.getTextPath()).exists()){
            text8.setText(readFile(postInfo8.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo8.getImg()).exists()){
            textImg8.setImage(new Image("file:"+postInfo8.getImg()));//设置图片
        }
        comment8.setText(String.valueOf(postInfo8.getComments()));//设置评论数
        like8.setText(String.valueOf(postInfo8.getLikes()));//设置点赞数
        tagText8.setText(String.valueOf(postInfo8.getTag()));//设置帖子标签
    }
    public void setPostDisplay9(){
        //第九个
        if(new File(postInfo9.getTextPath()).exists()){
            text9.setText(readFile(postInfo9.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo9.getImg()).exists()){
            textImg9.setImage(new Image("file:"+postInfo9.getImg()));//设置图片
        }
        comment9.setText(String.valueOf(postInfo9.getComments()));//设置评论数
        like9.setText(String.valueOf(postInfo9.getLikes()));//设置点赞数
        tagText9.setText(String.valueOf(postInfo9.getTag()));//设置帖子标签
    }
    public void setPostDisplay10(){
        //第十个
        if(new File(postInfo10.getTextPath()).exists()){
            text10.setText(readFile(postInfo10.getTitlePath()));//设置标题内容
        }
        if(new File(postInfo10.getImg()).exists()){
            textImg10.setImage(new Image("file:"+postInfo10.getImg()));//设置图片
        }
        comment10.setText(String.valueOf(postInfo10.getComments()));//设置评论数
        like10.setText(String.valueOf(postInfo10.getLikes()));//设置点赞数
        tagText10.setText(String.valueOf(postInfo10.getTag()));//设置帖子标签
    }
    public void setPostDisplayAll(List<String> fileIDs){//设置十个框的显示
        if(!fileIDs.isEmpty()){//目前帖子数不为0
            switch(fileIDs.size()){//有几个设置几个
                case 1:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostDisplay1();
                    text1.setVisible(true);
                    textImg1.setVisible(true);
                    comment1.setVisible(true);
                    commentImg1.setVisible(true);
                    like1.setVisible(true);
                    likeImg1.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagText1.setVisible(true);//标签数
                    break;
                case 2:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    break;
                case 3:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    break;
                case 4:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    break;
                case 5:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    break;
                case 6:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostInfo6("src/UserPosts/postObjects/"+fileIDs.get(5)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    setPostDisplay6();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    text6.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    textImg6.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    comment6.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    commentImg6.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    like6.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    likeImg6.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagImg6.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    tagText6.setVisible(true);
                    break;
                case 7:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostInfo6("src/UserPosts/postObjects/"+fileIDs.get(5)+".ser");
                    setPostInfo7("src/UserPosts/postObjects/"+fileIDs.get(6)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    setPostDisplay6();
                    setPostDisplay7();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    text6.setVisible(true);
                    text7.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    textImg6.setVisible(true);
                    textImg7.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    comment6.setVisible(true);
                    comment7.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    commentImg6.setVisible(true);
                    commentImg7.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    like6.setVisible(true);
                    like7.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    likeImg6.setVisible(true);
                    likeImg7.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagImg6.setVisible(true);
                    tagImg7.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    tagText6.setVisible(true);
                    tagText7.setVisible(true);
                    break;
                case 8:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostInfo6("src/UserPosts/postObjects/"+fileIDs.get(5)+".ser");
                    setPostInfo7("src/UserPosts/postObjects/"+fileIDs.get(6)+".ser");
                    setPostInfo8("src/UserPosts/postObjects/"+fileIDs.get(7)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    setPostDisplay6();
                    setPostDisplay7();
                    setPostDisplay8();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    text6.setVisible(true);
                    text7.setVisible(true);
                    text8.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    textImg6.setVisible(true);
                    textImg7.setVisible(true);
                    textImg8.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    comment6.setVisible(true);
                    comment7.setVisible(true);
                    comment8.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    commentImg6.setVisible(true);
                    commentImg7.setVisible(true);
                    commentImg8.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    like6.setVisible(true);
                    like7.setVisible(true);
                    like8.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    likeImg6.setVisible(true);
                    likeImg7.setVisible(true);
                    likeImg8.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagImg6.setVisible(true);
                    tagImg7.setVisible(true);
                    tagImg8.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    tagText6.setVisible(true);
                    tagText7.setVisible(true);
                    tagText8.setVisible(true);
                    break;
                case 9:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostInfo6("src/UserPosts/postObjects/"+fileIDs.get(5)+".ser");
                    setPostInfo7("src/UserPosts/postObjects/"+fileIDs.get(6)+".ser");
                    setPostInfo8("src/UserPosts/postObjects/"+fileIDs.get(7)+".ser");
                    setPostInfo9("src/UserPosts/postObjects/"+fileIDs.get(8)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    setPostDisplay6();
                    setPostDisplay7();
                    setPostDisplay8();
                    setPostDisplay9();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    text6.setVisible(true);
                    text7.setVisible(true);
                    text8.setVisible(true);
                    text9.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    textImg6.setVisible(true);
                    textImg7.setVisible(true);
                    textImg8.setVisible(true);
                    textImg9.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    comment6.setVisible(true);
                    comment7.setVisible(true);
                    comment8.setVisible(true);
                    comment9.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    commentImg6.setVisible(true);
                    commentImg7.setVisible(true);
                    commentImg8.setVisible(true);
                    commentImg9.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    like6.setVisible(true);
                    like7.setVisible(true);
                    like8.setVisible(true);
                    like9.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    likeImg6.setVisible(true);
                    likeImg7.setVisible(true);
                    likeImg8.setVisible(true);
                    likeImg9.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagImg6.setVisible(true);
                    tagImg7.setVisible(true);
                    tagImg8.setVisible(true);
                    tagImg9.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    tagText6.setVisible(true);
                    tagText7.setVisible(true);
                    tagText8.setVisible(true);
                    tagText9.setVisible(true);
                    break;
                default:
                    setPostInfo1("src/UserPosts/postObjects/"+fileIDs.get(0)+".ser");
                    setPostInfo2("src/UserPosts/postObjects/"+fileIDs.get(1)+".ser");
                    setPostInfo3("src/UserPosts/postObjects/"+fileIDs.get(2)+".ser");
                    setPostInfo4("src/UserPosts/postObjects/"+fileIDs.get(3)+".ser");
                    setPostInfo5("src/UserPosts/postObjects/"+fileIDs.get(4)+".ser");
                    setPostInfo6("src/UserPosts/postObjects/"+fileIDs.get(5)+".ser");
                    setPostInfo7("src/UserPosts/postObjects/"+fileIDs.get(6)+".ser");
                    setPostInfo8("src/UserPosts/postObjects/"+fileIDs.get(7)+".ser");
                    setPostInfo9("src/UserPosts/postObjects/"+fileIDs.get(8)+".ser");
                    setPostInfo10("src/UserPosts/postObjects/"+fileIDs.get(9)+".ser");
                    setPostDisplay1();
                    setPostDisplay2();
                    setPostDisplay3();
                    setPostDisplay4();
                    setPostDisplay5();
                    setPostDisplay6();
                    setPostDisplay7();
                    setPostDisplay8();
                    setPostDisplay9();
                    setPostDisplay10();
                    text1.setVisible(true);
                    text2.setVisible(true);
                    text3.setVisible(true);
                    text4.setVisible(true);
                    text5.setVisible(true);
                    text6.setVisible(true);
                    text7.setVisible(true);
                    text8.setVisible(true);
                    text9.setVisible(true);
                    text10.setVisible(true);
                    textImg1.setVisible(true);
                    textImg2.setVisible(true);
                    textImg3.setVisible(true);
                    textImg4.setVisible(true);
                    textImg5.setVisible(true);
                    textImg6.setVisible(true);
                    textImg7.setVisible(true);
                    textImg8.setVisible(true);
                    textImg9.setVisible(true);
                    textImg10.setVisible(true);
                    comment1.setVisible(true);
                    comment2.setVisible(true);
                    comment3.setVisible(true);
                    comment4.setVisible(true);
                    comment5.setVisible(true);
                    comment6.setVisible(true);
                    comment7.setVisible(true);
                    comment8.setVisible(true);
                    comment9.setVisible(true);
                    comment10.setVisible(true);
                    commentImg1.setVisible(true);
                    commentImg2.setVisible(true);
                    commentImg3.setVisible(true);
                    commentImg4.setVisible(true);
                    commentImg5.setVisible(true);
                    commentImg6.setVisible(true);
                    commentImg7.setVisible(true);
                    commentImg8.setVisible(true);
                    commentImg9.setVisible(true);
                    commentImg10.setVisible(true);
                    like1.setVisible(true);
                    like2.setVisible(true);
                    like3.setVisible(true);
                    like4.setVisible(true);
                    like5.setVisible(true);
                    like6.setVisible(true);
                    like7.setVisible(true);
                    like8.setVisible(true);
                    like9.setVisible(true);
                    like10.setVisible(true);
                    likeImg1.setVisible(true);
                    likeImg2.setVisible(true);
                    likeImg3.setVisible(true);
                    likeImg4.setVisible(true);
                    likeImg5.setVisible(true);
                    likeImg6.setVisible(true);
                    likeImg7.setVisible(true);
                    likeImg8.setVisible(true);
                    likeImg9.setVisible(true);
                    likeImg10.setVisible(true);
                    tagImg1.setVisible(true);//标签图标
                    tagImg2.setVisible(true);
                    tagImg3.setVisible(true);
                    tagImg4.setVisible(true);
                    tagImg5.setVisible(true);
                    tagImg6.setVisible(true);
                    tagImg7.setVisible(true);
                    tagImg8.setVisible(true);
                    tagImg9.setVisible(true);
                    tagImg10.setVisible(true);
                    tagText1.setVisible(true);//标签数
                    tagText2.setVisible(true);
                    tagText3.setVisible(true);
                    tagText4.setVisible(true);
                    tagText5.setVisible(true);
                    tagText6.setVisible(true);
                    tagText7.setVisible(true);
                    tagText8.setVisible(true);
                    tagText9.setVisible(true);
                    tagText10.setVisible(true);
                    break;
            }
        }
    }
    public void clear(){//设置透明不可见
        text1.setVisible(false);//帖子标题文本
        text2.setVisible(false);
        text3.setVisible(false);
        text4.setVisible(false);
        text5.setVisible(false);
        text6.setVisible(false);
        text7.setVisible(false);
        text8.setVisible(false);
        text9.setVisible(false);
        text10.setVisible(false);
        textImg1.setVisible(false);//帖子封面图片
        textImg2.setVisible(false);
        textImg3.setVisible(false);
        textImg4.setVisible(false);
        textImg5.setVisible(false);
        textImg6.setVisible(false);
        textImg7.setVisible(false);
        textImg8.setVisible(false);
        textImg9.setVisible(false);
        textImg10.setVisible(false);
        comment1.setVisible(false);//评论数
        comment2.setVisible(false);
        comment3.setVisible(false);
        comment4.setVisible(false);
        comment5.setVisible(false);
        comment6.setVisible(false);
        comment7.setVisible(false);
        comment8.setVisible(false);
        comment9.setVisible(false);
        comment10.setVisible(false);
        commentImg1.setVisible(false);//评论图标
        commentImg2.setVisible(false);
        commentImg3.setVisible(false);
        commentImg4.setVisible(false);
        commentImg5.setVisible(false);
        commentImg6.setVisible(false);
        commentImg7.setVisible(false);
        commentImg8.setVisible(false);
        commentImg9.setVisible(false);
        commentImg10.setVisible(false);
        like1.setVisible(false);//点赞数
        like2.setVisible(false);
        like3.setVisible(false);
        like4.setVisible(false);
        like5.setVisible(false);
        like6.setVisible(false);
        like7.setVisible(false);
        like8.setVisible(false);
        like9.setVisible(false);
        like10.setVisible(false);
        likeImg1.setVisible(false);//点赞图标
        likeImg2.setVisible(false);
        likeImg3.setVisible(false);
        likeImg4.setVisible(false);
        likeImg5.setVisible(false);
        likeImg6.setVisible(false);
        likeImg7.setVisible(false);
        likeImg8.setVisible(false);
        likeImg9.setVisible(false);
        likeImg10.setVisible(false);
        tagImg1.setVisible(false);//标签图标
        tagImg2.setVisible(false);
        tagImg3.setVisible(false);
        tagImg4.setVisible(false);
        tagImg5.setVisible(false);
        tagImg6.setVisible(false);
        tagImg7.setVisible(false);
        tagImg8.setVisible(false);
        tagImg9.setVisible(false);
        tagImg10.setVisible(false);
        tagText1.setVisible(false);//标签数
        tagText2.setVisible(false);
        tagText3.setVisible(false);
        tagText4.setVisible(false);
        tagText5.setVisible(false);
        tagText6.setVisible(false);
        tagText7.setVisible(false);
        tagText8.setVisible(false);
        tagText9.setVisible(false);
        tagText10.setVisible(false);
        text1.setText(null);//置空值
        text2.setText(null);
        text3.setText(null);
        text4.setText(null);
        text5.setText(null);
        text6.setText(null);
        text7.setText(null);
        text8.setText(null);
        text9.setText(null);
        text10.setText(null);
        textImg1.setImage(null);
        textImg2.setImage(null);
        textImg3.setImage(null);
        textImg4.setImage(null);
        textImg5.setImage(null);
        textImg6.setImage(null);
        textImg7.setImage(null);
        textImg8.setImage(null);
        textImg9.setImage(null);
        textImg10.setImage(null);
        tagText1.setText(null);
        tagText2.setText(null);
        tagText3.setText(null);
        tagText4.setText(null);
        tagText5.setText(null);
        tagText6.setText(null);
        tagText7.setText(null);
        tagText8.setText(null);
        tagText9.setText(null);
        tagText10.setText(null);
        comment1.setText(null);
        comment2.setText(null);
        comment3.setText(null);
        comment4.setText(null);
        comment5.setText(null);
        comment6.setText(null);
        comment7.setText(null);
        comment8.setText(null);
        comment9.setText(null);
        comment10.setText(null);
        like1.setText(null);
        like2.setText(null);
        like3.setText(null);
        like4.setText(null);
        like5.setText(null);
        like6.setText(null);
        like7.setText(null);
        like8.setText(null);
        like9.setText(null);
        like10.setText(null);
    }
    public void home(){//首页刷新
        if(new File("src/UserPosts/currentUser.ser").exists()){
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/UserPosts/currentUser.ser")))
            {
                try {//读取当前用户对象
                    userInfo = (UserInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Image userAvatar = new Image(userInfo.getAvatar());
        userImg.setImage(userAvatar);//设置用户头像
        followNum.setText(String.valueOf(userInfo.getFollowNum()));//设置关注数
        fansNum.setText(String.valueOf(userInfo.getFansNum()));//设置粉丝数
            List<Integer> fileIDs = new ArrayList<>();//装所有帖子id
        File dir = new File("src/UserPosts/postObjects");
        File[] files = dir.listFiles();//将帖子对象文件放入数组
        if(files!=null){//有帖子
            for(int i=0;i<files.length;i++){
                String fileName = files[i].getName();//获取文件名
                String fileID = fileName.substring(0,fileName.length()-4);//获取帖子文件id
                fileIDs.add(Integer.valueOf(fileID));
            }
        }
        Collections.sort(fileIDs);//排序
        Collections.reverse(fileIDs);//倒置，最新的在前
        List<String> IDs = fileIDs.stream().map(x -> x + "").collect(Collectors.toList());//将List<Integer>转List<String>
        clear();//清屏，设置透明
        setPostDisplayAll(IDs);//设置显示
        setTags();//设置标签
    }
    public void findTag(String tag){//查找符合tag的帖子
        clear();//清屏，设置透明
        List<String> fileIDs = new ArrayList<>();//装所有帖子id
        List<String> foundTagPostsIDs = new ArrayList<>();//装符合标签的帖子id
        File dir = new File("src/UserPosts/postObjects");
        File[] files = dir.listFiles();//将帖子对象文件放入数组
        if(files!=null){//有帖子
            for(int i=0;i<files.length;i++){
                String fileName = files[i].getName();//获取文件名
                String fileID = fileName.substring(0,fileName.length()-4);//获取帖子文件id
                fileIDs.add(fileID);
            }
        }
        if(!fileIDs.isEmpty()){//不为空
            PostInfo postObj = new PostInfo();
            for(String id : fileIDs){
                String postObjPath = "src/UserPosts/postObjects/"+ id + ".ser";
                if(new File(postObjPath).exists()){
                    try(
                            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(postObjPath)))
                    {
                        try {//读取帖子对象
                            postObj = (PostInfo) ois.readObject();
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(postObj.getTag().equals(tag) || postObj.getTag().contains(tag)){//匹配tag
                    foundTagPostsIDs.add(id);//将符合tag的帖子id装入
                }
            }
        }
        if(foundTagPostsIDs.isEmpty()){//未找到的情况
            String info = "未找到该标签下的文章！";
            Alert alert = new Alert(Alert.AlertType.INFORMATION, info,
                    new ButtonType("确定", ButtonBar.ButtonData.YES));
            alert.setHeaderText(null);
            alert.setTitle("提示");
            alert.show();
        }else{//找到有符合tag的帖子
            Collections.sort(foundTagPostsIDs);//排序
            Collections.reverse(foundTagPostsIDs);//倒置，最新的在前
            clear();
            setPostDisplayAll(foundTagPostsIDs);//设置显示
        }
    }
    public void findTag1(){//标签1
        findTag(tag1.getText());
    }
    public void findTag2(){//标签2
        findTag(tag2.getText());
    }
    public void findTag3(){//标签3
        findTag(tag3.getText());
    }
    public void findTag4(){//标签4
        findTag(tag4.getText());
    }

    public void manageTags(){//标签管理操作
        TagsManageController tagsManagement = new TagsManageController();
        try {
            tagsManagement.start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setTags(){
        ArrayList<String> tagsList = new ArrayList<>();
        String tag = null;
        try {
            FileInputStream fis = new FileInputStream("src/UserPosts/currentTags.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            while((tag = br.readLine())!=null){
                tagsList.add(tag);
            }
            fis.close();
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        tag1.setText(tagsList.get(0));
        tag2.setText(tagsList.get(1));
        tag3.setText(tagsList.get(2));
        tag4.setText(tagsList.get(3));
    }

    public void search(){//搜索
        String keyWord = searchBar.getText();//获取输入关键字
        List<String> fileIDs = new ArrayList<>();//装所有帖子id
        List<String> foundPostsIDs = new ArrayList<>();//装找到的帖子id
        File dir = new File("src/UserPosts/postTitles");
        File[] files = dir.listFiles();//将帖子标题文件放入数组
        if(files!=null){//有帖子
            for(int i=0;i<files.length;i++){
                String fileName = files[i].getName();//获取文件名
                String fileID = fileName.substring(0,fileName.length()-4);//获取帖子文件id
                fileIDs.add(fileID);
            }
        }
        for(String id : fileIDs){//遍历所有帖子标题
            String title = readFile("src/UserPosts/postTitles/"+ id +".txt");
            if(title.contains(keyWord) && !keyWord.isEmpty()){
                foundPostsIDs.add(id);//匹配到则将帖子id装入list
            }
        }
        int foundPostNums = foundPostsIDs.size();//找到多少个匹配的帖子
        if(foundPostNums == 0){//未找到
            clear();//清屏，设置透明
            String info = "未找到相关文章！";
            Alert alert = new Alert(Alert.AlertType.INFORMATION, info,
                    new ButtonType("确定", ButtonBar.ButtonData.YES));
            alert.setHeaderText(null);
            alert.setTitle("提示");
            alert.show();
        }else{//找到
            Collections.sort(foundPostsIDs);//排序
            Collections.reverse(foundPostsIDs);//倒置，最新的在前
            clear();//清屏，设置透明
            setPostDisplayAll(foundPostsIDs);
        }
    }
    public void toPostSite(PostInfo postInfo) {
        if(postInfo != null){
            //打开帖子详情
            try(
                    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src/UserPosts/currentPost.ser")))
            {   //写入当前帖子对象
                oos.writeObject(postInfo);
            } catch (IOException e) {
                e.printStackTrace();
            }
            PostSiteController postSite = new PostSiteController();//打开帖子详情页
            postSite.start(new Stage());
        }
    }
    public void toPost_1_Site() throws Exception {//第一个推荐框
        if(postInfo1!=null){
            toPostSite(postInfo1);//调用打开第一个帖子详情页
        }
    }
    public void toPost_2_Site() throws Exception {//第二个推荐框
        if(postInfo2!=null){
            toPostSite(postInfo2);//调用打开第二个帖子详情页
        }
    }
    public void toPost_3_Site() throws Exception {//第三个推荐框
        if(postInfo3!=null){
            toPostSite(postInfo3);//调用打开第三个帖子详情页
        }
    }
    public void toPost_4_Site() throws Exception {//第四个推荐框
        if(postInfo4!=null){
            toPostSite(postInfo4);//调用打开第四个帖子详情页
        }
    }
    public void toPost_5_Site() throws Exception {//第一个推荐框
        if(postInfo5!=null){
            toPostSite(postInfo5);//调用打开第五个帖子详情页
        }
    }
    public void toPost_6_Site() throws Exception {//第二个推荐框
        if(postInfo6!=null){
            toPostSite(postInfo6);//调用打开第六个帖子详情页
        }
    }
    public void toPost_7_Site() throws Exception {//第三个推荐框
        if(postInfo7!=null){
            toPostSite(postInfo7);//调用打开第七个帖子详情页
        }
    }
    public void toPost_8_Site() throws Exception {//第四个推荐框
        if(postInfo8!=null){
            toPostSite(postInfo8);//调用打开第八个帖子详情页
        }
    }
    public void toPost_9_Site() throws Exception {//第一个推荐框
        if(postInfo9!=null){
            toPostSite(postInfo9);//调用打开第九个帖子详情页
        }
    }
    public void toPost_10_Site() throws Exception {//第二个推荐框
        if(postInfo10!=null){
            toPostSite(postInfo10);//调用打开第十个帖子详情页
        }
    }
    public void toPersonHome(){
        String currentUserPath = "src/UserPosts/currentUser.ser";
        if(new File(currentUserPath).exists()){
            //打开用户首页
            try(
                    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(currentUserPath)))
            {
                try {//读取当前用户对象
                    userInfo = (UserInfo) ois.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                //在此加入打开personSite的代码
                UserSiteController userSite = new UserSiteController();
                try {
                    userSite.start(new Stage());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void toNewPostSite(){//打开新建页面
        NewPostSiteController newPostSite = new NewPostSiteController();
        NewPostSiteController.clearInfoForFile("src/UserPosts/currentDrafts.ser");
        try {
            newPostSite.start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void toDraftSite() {//打开草稿页面
        DraftsController draftSite = new DraftsController();
        try {
            draftSite.start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void toMyPostSite(){//打开我的帖子页面
     MyPostsController myPostsController = new MyPostsController();
        try {
            myPostsController.start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void toHistorySite(){//打开历史浏览页

    }
    public void toCollectionSite(){//打开收藏页
        try(
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/UserPosts/currentUser.ser")))
        {
            try {//读取当前用户对象
                userInfo = (UserInfo) ois.readObject();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            //在此加入打开收藏夹的代码
            CollectionController test = new CollectionController();
            try {
                test.start(new Stage());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void toFollowStage() throws Exception{
        try(
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/UserPosts/currentUser.ser")))
        {
            try {//读取当前用户对象
                userInfo = (UserInfo) ois.readObject();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            FollowController test = new FollowController();
            try {
                test.start(new Stage());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void toFansStage() throws Exception {
        try(
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/UserPosts/currentUser.ser")))
        {
            try {//读取当前用户对象
                userInfo = (UserInfo) ois.readObject();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            FansController test = new FansController();
            try {
                test.start(new Stage());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
